<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		
		<script type="text/javascript">
			
			/*
			 * 深度克隆
			 * 
			 */
			
			var obj = {
				name : "abc",
				age : 123,
				card : ['visa','master'],
				wife : {
					name : "bcd",
					son : {
						name : "aaa"
					}
				}
			}
			
			//遍历对象 for(var prop in obj)
			//1.判断是不是原始值 typeof() object
			//2.判断是数组还是对象 toString() instanceof/constructor 跨域
			//3.建立相应的数组或者对象
			
			var obj1 = {};
			
			function deepClone(origin,target){
				var target = target || {},
					toStr = Object.prototype.toString,
					arrStr = "[object Array]";
				
				for(var prop in origin){
					if(origin.hasOwnProperty(prop)){
						if(origin[prop] !== "null" && typeof((origin[prop])) == 'object'){
							target[prop] = toStr.call(origin[prop]) == arrStr ? []:{};
//							if(toStr.call(origin[prop]) ==arrStr){
//								target[prop] = [];
//							}else{
//								target[prop] = {};
//							}
							deepClone(origin[prop],target[prop]);
						}else{
							target[prop] = origin[prop];
						}
					}
				}
				
				return target;
			}
			
			
			
		</script>
	</body>
</html>
